const mongoose = require('mongoose');

const loginType = new mongoose.Schema({
  username: String,
  password: String,
})
const tabType= new mongoose.Schema({
  name: String,
  price: Number,
  img: String,
  num: Number,
  type: String,
  details: String,
})
const floorLeft= new mongoose.Schema({
  name: String,
})
const floorRight= new mongoose.Schema({
  title: String,
  price: String,
  num: Number,
  img: String,
  img1: String,
  pid:Number
})

const loginModel = mongoose.model('login', loginType, 'login');
const tabModel = mongoose.model('goods', tabType, 'goods');
const floorLeftModel = mongoose.model('floorLeft', floorLeft, 'floorLeft');
const floorRightModel = mongoose.model('floorRight', floorRight, 'floorRight');
module.exports = {
  init: () => {
    mongoose.
      connect('mongodb://127.0.0.1:27017/shopping')
      .then(() => {
        console.log('数据库连接成功');
      })
      .catch(() => {
        console.log('数据库连接失败');
      })
  },
  getLogin: async (obj)=>{
    console.log(obj);
    let arr= await loginModel.find(obj);
    return arr;
  },
  changeTab: async(type)=>{
    console.log(type);
    let arr= await tabModel.find({type:type})
    return arr;
  },
  getfloorLeft:async()=>{
    let arr= await floorLeftModel.find();
    return arr;
  },
  getfloorRight:async()=>{
    let arr= await floorRightModel.find();
    return arr;
  }
}